package com.geekjob1120.geekjob1120pay.repository;

import com.geekjob1120.geekjob1120pay.modle.Pay;
import org.hibernate.annotations.DynamicUpdate;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.sql.SQLTimeoutException;

@DynamicUpdate
public interface PayRepository extends CrudRepository<Pay,Long> {

    Pay findByOrderId(String ordID);

//    @Lock(LockModeType.PESSIMISTIC_WRITE)
//    @QueryHints({@QueryHint(name = "javax.persistence.lock.timeout",value = "1000")})
    @Transactional(propagation = Propagation.MANDATORY)
    @Query(value = "select * from t_pay p where p.id = ?1 for update nowait",nativeQuery = true)
    Pay forupdate( Long id) throws SQLTimeoutException;

}
